package com.booking.common.dto;

import lombok.Data;

import javax.validation.Valid;
import java.io.Serializable;

/**
 * @author Qikai.Lin
 * @date 2023/4/23
 */
@Data
public class PageReq<T> implements Serializable {
    public static final int DEFAULT_SIZE = 500;

    private int size;
    private int current;
    private @Valid T condition;
    public PageReq() {
        this.size = 10;
        this.current = 1;
    }

    public PageReq(int size, int current) {
        if (size >= DEFAULT_SIZE) {
            size = DEFAULT_SIZE;
        }

        this.size = size;
        this.current = current;
    }

    public void forceSetSize(int size) {
        this.size = size;
    }

    public int getSize() {
        return this.size <= 0 ? 10 : this.size;
    }

    public void setSize(int size) {
        this.size = Math.min(size, DEFAULT_SIZE);
    }

    public int getCurrent() {
        return this.current <= 0 ? 1 : this.current;
    }

    public void setCurrent(int current) {
        this.current = current;
    }
}